package com.ztjc.day02_storage.util;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by pro on 15/10/7.
 */
public class SharedPerferencesUtil {

    /**
     * 保存用户信息
     *
     * @param context
     * @param account
     * @param pass
     * @return
     */
    public static boolean saveAccount(Context context, String account, String pass) {
        try {
            context.getSharedPreferences("account", Context.MODE_PRIVATE).edit().putString("account", account).putString("pass", pass).commit();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 获取用户信息
     *
     * @param context
     * @return
     */
    public static Map<String, String> getAccount(Context context) {
        SharedPreferences account = context.getSharedPreferences("account", Context.MODE_PRIVATE);
        Map<String, String> result = new HashMap<>();
        result.put("account", account.getString("account", ""));
        result.put("pass", account.getString("pass", ""));
        return result;
    }
}
